package com.zhiyou100.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.IService.IserviceAP;
import com.zhiyou100.entity.adminP.TbAdmin;

@Controller
public class adminPowerController {

	@Resource
	private IserviceAP service;
	@Autowired
	private HttpServletRequest request;
	
	
	@RequestMapping("adminPower.do")
	public String ap(@RequestParam(required=true,defaultValue="1")Integer page,TbAdmin admin,String heihei) {
		PageHelper.startPage(page,6);
		if (null!=heihei&&!heihei.equals("null")) {
			admin.setAdminPowerId(Integer.parseInt(heihei));
		}
		List<TbAdmin> list = service.select(admin);
		PageInfo<TbAdmin> p = new PageInfo<TbAdmin>(list);
		request.setAttribute("page", p);
		request.setAttribute("admins", list);
		return "adminPower";
	}
	@ResponseBody
	@RequestMapping("updateAdmin.do")
	public String updateAdmin(TbAdmin admin) {
		boolean b = service.update(admin);
		return b?"0":"1";
	}
	@RequestMapping("deladmin.do")
	public String deladmin(TbAdmin admin) {
		boolean b = service.del(admin);
		return "forward:adminPower.do";
	}
}
